package com.youens.navigationdrawertest.ui.review

import android.net.Uri
import android.os.Bundle
import android.util.DebugUtils
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager

import androidx.lifecycle.ViewModelProviders
import androidx.viewpager.widget.ViewPager
import com.youens.navigationdrawertest.MainActivity
import com.youens.navigationdrawertest.R
import com.youens.navigationdrawertest.database.DataBaseUtils
import com.youens.navigationdrawertest.ui.favorite.Record

class ReviewFragment : Fragment() {

    private lateinit var reviewViewModel: ReviewViewModel
    private lateinit var mAdapter: FragementAdapter
    private lateinit var viewPager:ViewPager
    private lateinit var fm:FragmentManager
    private lateinit var databaseUtil: DataBaseUtils
    private lateinit var data:MutableList<Record>
    private var flag = false

    override fun onStart() {
        Log.d("TAG","ReviewFragment onStart")
        super.onStart()
        viewPager = view!!.findViewById(R.id.viewPager2)
        viewPager.adapter = mAdapter


    }
    override fun onCreate(savedInstanceState: Bundle?) {
        Log.d("TAG","ReviewFragment onCreate")
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_main)
        //activity!!.setContentView(R.layout.fragment_review)
        databaseUtil = (activity as MainActivity).getDataBaseUtils()
        //fm = activity!!.supportFragmentManager
        fm = childFragmentManager
        data = databaseUtil.getWordsRandomly(100)

    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        reviewViewModel =
            ViewModelProviders.of(this).get(ReviewViewModel::class.java)
        val root = inflater.inflate(R.layout.fragment_review, container, false)
        //val textView: TextView = root.findViewById(R.id.text_tools)
        //reviewViewModel.text.observe(this, Observer {
        //    textView.text = it
        //})
        Log.d("TAG","ReviewFragment onCreateView")
        if (arguments!=null){
            flag = arguments!!.getBoolean("flag")
            if (flag){
                data = databaseUtil.getWongWordsRandomly(100)
            }
        }
        mAdapter = FragementAdapter(fm,data,flag)

        return root
    }

}